<?php 

namespace app\Index\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\Session;

class Pinglun extends Controller
{
	public function ping()
	{


		 $this->assign('phone',Session::get('user.phone') );
         $p = Request::instance()->post();//接收数据

	     if(empty($p['pinglun'])){return $this->success('请填写值');}

         $id = $p['mid'];
		  if (Session::get('user.phone')) {
		  	  $result = Db::name('tb_users')->where('phone',Session::get('user.phone'))->select();
		  	  // var_dump($p);die;
		  	  $results=$result[0];
		  	  $time=date('Y-m-d H:i:s',time());
		  	  //处理数据
		  	   $data = ['mid'=>$p['mid'],
                        'uid'=>$results['id'],
                        'createtime'=>$time,
                        'pinglun'=>$p['pinglun'],
                        'oid'=>$p['mid'],
             
                  
                      ];
               

		       $result= Db::name('to_comment')->data($data)->insert();
              

		       if ($result >0) {
		          return $this->success('评论成功',url('index/Index/song_details?id='.$id));
		       }else{
		          return $this->success('评论失败');
		       }
         

		  	  // var_dump($p);die;
		
				}else{
					return $this->success('请先登录！！！',url('index/Index/song_details?id='.$id));
				}
			}

        
		    //评论删除
		   public function delete($id)
		   {

		   	 $result = Db::name('to_comment')->delete($id);
		   	 $list = Db::name('to_recomment')->where('cid',$id)->delete();
		     
		     if ($result >0 ) {
		       $info['status'] = true;
		     }else{
		       $info['status'] = false;
		     }

		     return $info;




		   	 return $this->fetch('song_details/song_details');
		   }
		   
		   
		   //回复
		   public function hf()
		   {
		   	    if (Session::get('user.phone')){
		   	    	
                $p = Request::instance()->post();//接收数据
		   	    // var_dump($p);die;
		   	    $id=$p['mid'];
		   	    $time=date('Y-m-d H:i:s',time());
		   	    //处理数据
		  	    $data = ['cid'=>$p['cid'],
                        'createtime'=>$time,
                        'huifu'=>$p['pinglun'],
                      
             
                  
                      ];

               $result= Db::name('to_recomment')->data($data)->insert();
              

		       if ($result >0) {
		          return $this->success('回复成功',url('index/Index/song_details?id='.$id));
		       }else{
		          return $this->success('回复失败');
		       }



		   	   }else{

                     	
                  $p = Request::instance()->post();//接收数据
                  $id=$p['mid'];
		   	   	  return $this->success('请先登录！！！',url('index/Index/song_details?id='.$id));
		   	   }
		   	   

               
		   	    
		   } 

}